home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /***************************************************************************
- *
- * @(#) - BZVIEWLOGO - View BZ logo files
- *
- * $Id: bzviewlogo.c,v 1.3 1993/08/11 19:46:43 adele Exp $
- *
- * Chris Fouts - Silicon Graphics, Inc.
- * October, 1991
- **************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
-
- #include <gl/gl.h>
- #include <gl/device.h>
-
- static char *version_id = "$Id: bzviewlogo.c,v 1.3 1993/08/11 19:46:43 adele Exp $" ;
-
-
- #define BZL_BGNTMESH 0
- #define BZL_SWAPTMESH 1
- #define BZL_ENDBGNTMESH 2
- #define BZL_RETENDTMESH 3
- #define BZL_LEFTSIDE 4
- #define BZL_RIGHTSIDE 5
- #define BZL_NOSIDE 6
- #define LOGO_SIZE 500
-
- typedef unsigned long GL_Object ;
-
- /* BEGIN PROTOTYPES -S bzviewlogo.c */
- static GL_Object create_logo( unsigned char *logodata ) ;
- static int read_logo( const char *filename ) ;
- /* END PROTOTYPES -S bzviewlogo.c */
-
- void main(
- int argc,
- char **argv
- )
- {
- GL_Object logo ;
- int redraw = 1 ;
- short val ;
-
- foreground() ;
- keepaspect( 1, 1 ) ;
- winopen( argv[0] ) ;
-
- logo = read_logo( argv[1] ) ;
-
- qdevice( ESCKEY ) ;
-
- while( logo ) {
- if( redraw ) {
- reshapeviewport() ;
- ortho2( -10., 265., -10., 265. ) ;
- redraw = 0 ;
- color( WHITE ) ;
- clear() ;
- color( BLACK ) ;
- callobj( logo ) ;
- }
- while( qtest() ) {
- switch( qread( &val ) ) {
-
- case REDRAW :
- redraw = 1 ;
- break ;
-
- case ESCKEY :
- logo = 0 ;
- break ;
- }
- }
- }
-
- }
-
-
-
- static int read_logo(
- const char *filename
- )
- {
- FILE *f ;
- char line[128] ;
- unsigned char logodata[LOGO_SIZE] ;
- int n = 0 ;
- int npts ;
- int x ;
- int y ;
- int version ;
- int global = 1 ;
- int ln = 0 ;
- int nbtm = 0 ;
-
- if( ( f = fopen( filename, "r" ) ) == NULL ) {
- perror( filename ) ;
- return( 0 ) ;
- }
-
- fgets( line, sizeof( line ), f ) ;
- ln++ ;
-
- if( strcmp( line, "# BZLOGO Version 1.1\n" ) == 0 ) {
- version = 11 ;
- }
- else if( strcmp( line, "# BZLOGO Version 1.0\n" ) == 0 ) {
- version = 10 ;
- global = 0 ;
- }
- else {
- fclose( f ) ;
- fprintf( stderr, "read_logo: bad magic number in logo file.\n" ) ;
- return( 0 ) ;
- }
-
- while( 1 ) {
- if( fgets( line, sizeof( line ), f ) == NULL ) {
- fclose( f ) ;
- fprintf( stderr, "read_logo: premature end of file.\n" ) ;
- return( 0 ) ;
- }
- ln++ ;
-
- if( strcmp( line, "BGNTMESH\n" ) == 0 ) {
- if( nbtm > 0 ) {
- fprintf( stderr, "read_logo: error on line %d -- embedded call "
- "to BGNTMESH (use ENDBGNTMESH)\n", ln ) ;
- return( 0 ) ;
- }
- nbtm = 1 ;
- logodata[n++] = BZL_BGNTMESH ;
- global = 0 ;
- }
- else if( strcmp( line, "SWAPTMESH\n" ) == 0 ) {
- logodata[n++] = BZL_SWAPTMESH ;
- global = 0 ;
- }
- else if( strcmp( line, "ENDBGNTMESH\n" ) == 0 ) {
- logodata[n++] = BZL_ENDBGNTMESH ;
- global = 0 ;
- }
- else if( strcmp( line, "RETENDTMESH\n" ) == 0 ) {
- logodata[n++] = BZL_RETENDTMESH ;
- global = 0 ;
- break ;
- }
- else if( global == 1 && strcmp( line, "LEFTSIDE\n" ) == 0 ) {
- logodata[n++] = BZL_LEFTSIDE ;
- }
- else if( global == 1 && strcmp( line, "RIGHTSIDE\n" ) == 0 ) {
- logodata[n++] = BZL_RIGHTSIDE ;
- }
- else {
- fclose( f ) ;
- fprintf( stderr, "read_logo: error reading logo file.\n" ) ;
- return( 0 ) ;
- }
-
- if( global ) {
- npts = 0 ;
- }
- else {
- if( fscanf( f, "%d", &npts ) != 1 || npts < 1 ) {
- fclose( f ) ;
- fprintf( stderr, "read_logo: error reading logo file.\n" ) ;
- return( 0 ) ;
- }
- ln++ ;
-
- /*
- * Check size of logo:
- *
- * NUMBER_PTS_ALREADY + NEXT_CMD + N_PTS + N_PTS * 2
- */
- if( n + 2 + 2 * npts >= LOGO_SIZE ) {
- fclose( f ) ;
- fprintf( stderr, "read_logo: logo too big "
- "(maximum of %d words)\n", LOGO_SIZE ) ;
- return( 0 ) ;
- }
-
- logodata[n++] = npts ;
-
- while( npts-- ) {
- if( fscanf( f, "%d %d", &x, &y ) != 2 || x < 0 || y < 0 ||
- x > 255 || y > 255 ) {
- fclose( f ) ;
- fprintf( stderr, "read_logo: error reading logo file.\n" ) ;
- return( 0 ) ;
- }
- ln++ ;
- logodata[n++] = x ;
- logodata[n++] = y ;
- }
-
- /*
- * Get trailing line feed.
- */
- if( fgetc( f ) != '\n' ) {
- fclose( f ) ;
- fprintf( stderr, "read_logo: error reading logo file.\n" ) ;
- return( 0 ) ;
- }
- }
- }
-
- fclose( f ) ;
-
- return( create_logo( logodata ) ) ;
- }
-
-
-
- static GL_Object create_logo(
- unsigned char *logodata
- )
- {
- GL_Object obj = 1 ;
- unsigned char glyph ;
- int npts ;
- float pt[2] ;
- int expect_points ;
-
- makeobj( obj ) ;
-
- while( ( glyph = *(logodata++) ) != BZL_RETENDTMESH ) {
- switch( glyph ) {
- case BZL_BGNTMESH :
- bgntmesh() ;
- expect_points = 1 ;
- break ;
- case BZL_SWAPTMESH :
- swaptmesh() ;
- expect_points = 1 ;
- break ;
- case BZL_ENDBGNTMESH :
- endtmesh() ;
- bgntmesh() ;
- expect_points = 1 ;
- break ;
- case BZL_LEFTSIDE :
- case BZL_RIGHTSIDE :
- expect_points = 0 ;
- break ;
- default :
- closeobj() ;
- delobj( obj ) ;
- fprintf( stderr, "create_logo: bad logo info\n" ) ;
- return( 0 ) ;
- }
-
- if( expect_points ) {
- npts = *(logodata++) ;
- while( npts > 0 ) {
- pt[0] = *(logodata++) ;
- pt[1] = *(logodata++) ;
- v2f( pt ) ;
- npts-- ;
- }
- }
- }
- endtmesh() ;
- closeobj() ;
-
- return( obj ) ;
- }
-
-
-
-